﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VNPT.Utility.Profile;

namespace VNPT.Data
{
    public static class DataSetting
    {
        public static string CONNECTSTRING
        {
            get
            {
                string strCnn = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})));uid={3};pwd={4};";
                //return "Data Source=VNPT06;User Id=system;Password=abc123;";//
                return string.Format(strCnn, HOST, PORT, SERVICE_NAME, UID, PWD);
            }
        }

        public static string CONNECTSTRING_TNS_NAME
        {
            get
            {
                if (IS_OK_TNS)
                {
                    string strCnn = "Data Source={0};User Id={1};Password={2};";
                    return string.Format(strCnn, TNS_NAME, UID, PWD);
                }
                else
                {
                    return null;// new Data.fOracleConnect_TNS().GetConnectionString();
                }
                
            }
        }

        public static bool IS_OK
        {
            get
            {
                return (!string.IsNullOrWhiteSpace(PWD) &&
                    !string.IsNullOrWhiteSpace(UID) &&
                    !string.IsNullOrWhiteSpace(SERVICE_NAME) &&
                    !string.IsNullOrWhiteSpace(HOST));
            }
        }
        public static bool IS_OK_TNS
        {
            get
            {
                return (!string.IsNullOrWhiteSpace(PWD) &&
                    !string.IsNullOrWhiteSpace(UID) &&
                    !string.IsNullOrWhiteSpace(TNS_NAME));
            }
        }
        public static string PWD
        {
            get
            {
                Xml xml = new Xml();
                var t = xml.GetValue("ORC_CNN", "PWD", "");
                return VNPT.Utility.Security.EncryptandDecrypt.Decrypt(t);
            }
            set
            {
                Xml xml = new Xml();
                xml.SetValue("ORC_CNN", "PWD", VNPT.Utility.Security.EncryptandDecrypt.Encrypt(value));
            }
        }

        public static string UID
        {
            get
            {
                Xml xml = new Xml();
                var t = xml.GetValue("ORC_CNN", "UID", "");
                return VNPT.Utility.Security.EncryptandDecrypt.Decrypt(t); 
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    Xml xml = new Xml();
                    xml.SetValue("ORC_CNN", "UID", VNPT.Utility.Security.EncryptandDecrypt.Encrypt(value));
                }
            }
        }

        public static bool  IS_SAVE
        {
            get
            {
                Xml xml = new Xml();
                return xml.GetValue("ORC_CNN", "IS_SAVE", false);
            }
            set
            {
                Xml xml = new Xml();
                xml.SetValue("ORC_CNN", "IS_SAVE", value);
            }
        }

        public static string SERVICE_NAME
        {
            get
            {
                Xml xml = new Xml();
                return xml.GetValue("ORC_CNN", "SERVICE_NAME", "");
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    Xml xml = new Xml();
                    xml.SetValue("ORC_CNN", "SERVICE_NAME", value);
                }
            }
        }

        public static int PORT
        {
            get
            {
                Xml xml = new Xml();
                return xml.GetValue("ORC_CNN", "PORT", 1521);
            }
            set
            {
                Xml xml = new Xml();
                xml.SetValue("ORC_CNN", "PORT", value);
            }
        }
        public static string TNS_NAME
        {
            get
            {
                Xml xml = new Xml();
                return xml.GetValue("ORC_CNN", "TNS_NAME", "");
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    Xml xml = new Xml();
                    xml.SetValue("ORC_CNN", "TNS_NAME", value);
                }
            }
        }
        public static string HOST
        {
            get
            {
                Xml xml = new Xml();
                return xml.GetValue("ORC_CNN", "HOST", "");
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    Xml xml = new Xml();
                    xml.SetValue("ORC_CNN", "HOST", value);
                }
            }
        }
    }
}
